package com.bus.service.impl;

import com.bus.dao.GoodsDao;
import com.bus.entity.Goods;
import com.bus.service.GoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.common.DataGridView;
import com.bus.vo.GoodsVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Resource
    private GoodsDao goodsDao;

    @Override
    public DataGridView selectAllGoods(GoodsVo goodsVo) {
        PageHelper.startPage(goodsVo.getPage(),goodsVo.getLimit());
        List<Goods> goods = goodsDao.selectAllGoods(goodsVo);
        return new  DataGridView(new PageInfo<>(goods).getTotal(),goods);
    }

    @Override
    public List<Goods> selectAllById(String providerName) {
        return goodsDao.selectAllById(providerName);
    }

    @Override
    public List<Goods> selectPrice(String goodsName) {
        return goodsDao.selectPrice(goodsName);
    }

    @Override
    public int save(GoodsVo goodsVo) {
        return goodsDao.insertGoods(goodsVo);
    }

    @Override
    public Goods getById(Integer goodsId) {
        return goodsDao.getGoodsById(goodsId);
    }

    @Override
    public int updateById(GoodsVo goodsVo) {
        return goodsDao.updateGoodsById(goodsVo);
    }

    @Override
    public int deleteById(Integer goodsId) {
        return goodsDao.deleteGoodsById(goodsId);
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        goodsDao.deleteBatchByIds(ids);
    }

    @Override
    public List<Goods> selectGoodsById(Integer providerId) {
        return goodsDao.getGoodsByProviderId(providerId);
    }

    @Override
    public List<Goods> selectGoods() {
        return goodsDao.selectGoods();
    }

    @Override
    public int updateNum(Integer goodsId, Integer num) {
        return goodsDao.updateNum(goodsId,num);
    }


}
